package com.ly.cloud.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.GradeProfessionalInfoDto;
import com.ly.cloud.dto.ProfessionalInfoDto;
import com.ly.cloud.dto.UpdateCampusDto;
import com.ly.cloud.service.GradeProfessionalInfoService;
import com.ly.cloud.service.ProfessionalInfoService;
import com.ly.cloud.vo.*;
import com.ly.cloud.web.utils.WebResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description: 年级专业
 * @Author: pengshiqng
 * @Date: Create in 2018/12/14
 */
@RestController
@RequestMapping("/gradeProInfo")
@Api("年级专业Controller")
public class GradeProfessionalInfoController {

    @Autowired
    private GradeProfessionalInfoService gradeProfessionalInfoService ;

    @Autowired
    private ProfessionalInfoService professionalInfoService ;



    /**
     * 分页+条件查询
     */
    @RequestMapping(value = "/queryPageList", method = RequestMethod.GET)
    public WebResponse<PageInfo<GradeProfessionalInfoVo>> queryPageList( @RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
                                                                         GradeProfessionalInfoDto dto){
        Page<GradeProfessionalInfoVo> page = gradeProfessionalInfoService.selectPage(new Page<GradeProfessionalInfoVo>(pageNum, pageSize), dto);
        return new WebResponse<PageInfo<GradeProfessionalInfoVo>>().success(PageInfo.toPageInfo(page));
    }

    /**
     * 根据id删除
     */
    @RequestMapping(value = "/deleteById/{id}", method = RequestMethod.POST)
    public WebResponse<Integer> deleteById(@PathVariable("id") String id){
        int result = gradeProfessionalInfoService.deleteById(id) ;
        return new WebResponse<Integer>().success(result);
    }

    /**
     * 根据id批量删除
     */
    @RequestMapping(value = "/deleteByIds", method = RequestMethod.POST)
    public WebResponse<Integer> deleteByIds(@RequestBody List<String> ids){
        int result = gradeProfessionalInfoService.deleteByIds(ids) ;
        return new WebResponse<Integer>().success(result);
    }


    /**
     * 修改
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public WebResponse<Integer> update(@RequestHeader(required=false,value = "loginUserName")String loginUserName, @RequestBody GradeProfessionalInfoDto dto){
        int result = gradeProfessionalInfoService.update(loginUserName,dto);
        return new WebResponse<Integer>().success(result);
    }


    /**
     * 查询所有校区
     */
    @RequestMapping(value = "/findAllCampus", method = RequestMethod.GET)
    public WebResponse<List<CampusSelectVo>> findAllCampus(){
        List<CampusSelectVo> list = gradeProfessionalInfoService.findAllCampus();
        return new WebResponse<List<CampusSelectVo>>().success(list) ;
    }


    /**
     * 设置校区
     */
    @RequestMapping(value = "/updateCampus", method = RequestMethod.POST)
    public WebResponse<Boolean> updateCampus(@RequestHeader(required=false,value = "loginUserName") String loginUserName, @RequestBody UpdateCampusDto dto){
        gradeProfessionalInfoService.updateCampus(loginUserName , dto.getList() , dto.getCampus());
        return new WebResponse<Boolean>().success(true) ;
    }


    /**
     * 弹出新增专业界面 分页+条件查询
     */
    @RequestMapping(value = "/showPop", method = RequestMethod.POST)
    public WebResponse<PageInfo<ProfessionalInfoVo>> showPop( @RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize, @RequestBody ProfessionalInfoDto dto){
        Page<ProfessionalInfoVo> page = professionalInfoService.selectPage(new Page<ProfessionalInfoVo>(pageNum, pageSize), dto);
        return new WebResponse<PageInfo<ProfessionalInfoVo>>().success(PageInfo.toPageInfo(page));
    }

    /**
     * 新增
     * @param ids 新增的专业主键集合
     * @param grade 年级
     * @param campus 校区
     * @return
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public WebResponse<Integer> insert(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody List<String> ids,@RequestParam("grade") String grade, @RequestParam("campus") String campus){
        int result = gradeProfessionalInfoService.insert(loginUserName,ids, grade, campus);
        return new WebResponse<Integer>().success(result) ;
    }


    /**
     * 复制
     * @param ids
     * @param targetGrade
     * @return
     */
    @RequestMapping(value = "/cppy", method = RequestMethod.POST)
    public WebResponse<Integer> cppy(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody List<String> ids, @RequestParam("targetGrade") String targetGrade){
        int result = gradeProfessionalInfoService.copy(loginUserName,ids, targetGrade);
        return new WebResponse<Integer>().success(result) ;
    }

    /** 
   	 * Method Name: selectNjZyByNj
   	 * Description:  
   	 * 根据年级查询年级专业，下拉列表
   	 * @param nj 年级
   	 * @return 年级专业列表
   	 * @author luhuacong
   	 * @date: 2018年12月20日
   	 */
    @RequestMapping(value = "/selectNjZyByNj", method = RequestMethod.GET)
    public WebResponse<List<NjzySelectVo>> selectNjZyByNj(@RequestParam(required=false) String nj){
    	 List<NjzySelectVo> voList = gradeProfessionalInfoService.selectNjZyByNj(nj);
    	 return new WebResponse<List<NjzySelectVo>>().success(voList) ;
    }

    /**
     * @Description: 根据年级和学院查询年级专业
     * @Author: pengshiqing
     * @CreateDate: 2018/12/25
     */
    @RequestMapping(value = "/findNjzyByNjAndXy", method = RequestMethod.GET)
    public WebResponse<List<NjzySelectVo>> findNjzyByNjAndXy(@RequestParam(required = false,value = "nj")String nj,
                                                             @RequestParam(required = false,value = "xy")String xy) {
        List<NjzySelectVo> List = gradeProfessionalInfoService.findNjzyByNjAndXy(nj, xy);
        return new WebResponse<List<NjzySelectVo>>().success(List);
    }

    /**
    * @Description: 通过年级专业代码查询年级专业信息
    * @author: pengshiqing
    * @date: 2019/1/7
    */
    @RequestMapping(value = "/findByNjzydm", method = RequestMethod.GET)
    public WebResponse<GradeProfessionalInfoVo> findByNjzydm(@RequestParam String njzydm) {
        GradeProfessionalInfoVo vo = gradeProfessionalInfoService.findByNjzydm(njzydm);
        return new WebResponse<GradeProfessionalInfoVo>().success(vo);
    }

    
}
